﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GTA
{
    public partial class FrmTaskFields : BaseForm
    {
        #region Starting Form
        public FrmTaskFields()
        {
            InitializeComponent();
        }
        private void FrmTaskFields_Load(object sender, EventArgs e)
        {
            StartForm();
        }
        private void StartForm()
        {
            LoadTaskFields();
        }
        #endregion

        #region Events
        private void lstFields_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstFields, GetLstFieldColumnType(e.Column), ref columnOrder, ref sortOrder, e.Column);
        }
        #endregion

        #region Methods
        private void LoadTaskFields()
        {
            try
            {
                BusinessLogic.GTA bl = new BusinessLogic.GTA();
                List<BusinessEntity.TaskField> fields = bl.ListFieldDefinitions();
                lstFields.Items.Clear();
                if (fields != null && fields.Count > 0)
                {
                    foreach (BusinessEntity.TaskField item in fields)
                    {
                        ListViewItem lstItem = new ListViewItem(item.Id.ToString());
                        lstItem.SubItems.Add(item.Name);
                        lstItem.SubItems.Add(item.ReferenceName);
                        lstItem.SubItems.Add(item.FieldTypeDefinition.ToString());
                        lstFields.Items.Add(lstItem);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException("Carregar a Lista de Campos do TeamSystem", ex);
            }
        }
        private OrdenacaoListView.Tipo GetLstFieldColumnType(int column)
        {
            OrdenacaoListView.Tipo tipo;
            switch (column)
            {
                case 0:
                    tipo = OrdenacaoListView.Tipo.Numerica;
                    break;
                case 1:
                    tipo = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 2:
                    tipo = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                case 3:
                    tipo = OrdenacaoListView.Tipo.Alfabetica;
                    break;
                default:
                    tipo = OrdenacaoListView.Tipo.Alfabetica;
                    break;
            }
            return tipo;
        }
        #endregion
    }
}
